home *** CD-ROM | disk | FTP | other *** search
/ PC Format (PL) 2015 August / PC_Format_082015.iso / Pełne wersje / F-Secure FREEDOME VPN 1.0.11 / Freedome.exe / QtGraphicalEffects / private / FastMaskedBlur.qml < prev    next >
Text File  |  2015-04-13  |  11KB  |  333 lines

  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
  4. ** Contact: http://www.qt-project.org/legal
  5. **
  6. ** This file is part of the Qt Graphical Effects module.
  7. **
  8. ** $QT_BEGIN_LICENSE:BSD$
  9. ** You may use this file under the terms of the BSD license as follows:
  10. **
  11. ** "Redistribution and use in source and binary forms, with or without
  12. ** modification, are permitted provided that the following conditions are
  13. ** met:
  14. **   * Redistributions of source code must retain the above copyright
  15. **     notice, this list of conditions and the following disclaimer.
  16. **   * Redistributions in binary form must reproduce the above copyright
  17. **     notice, this list of conditions and the following disclaimer in
  18. **     the documentation and/or other materials provided with the
  19. **     distribution.
  20. **   * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
  21. **     of its contributors may be used to endorse or promote products derived
  22. **     from this software without specific prior written permission.
  23. **
  24. **
  25. ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26. ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27. ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  28. ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  29. ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  30. ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  31. ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  32. ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  33. ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  34. ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
  36. **
  37. ** $QT_END_LICENSE$
  38. **
  39. ****************************************************************************/
  40.  
  41. import QtQuick 2.0
  42.  
  43. Item {
  44.     id: rootItem
  45.     property variant source
  46.     property variant maskSource
  47.     property real blur: 0.0
  48.     property bool transparentBorder: false
  49.     property bool cached: false
  50.  
  51.     SourceProxy {
  52.         id: sourceProxy
  53.         input: rootItem.source
  54.     }
  55.  
  56.     SourceProxy {
  57.         id: maskSourceProxy
  58.         input: rootItem.maskSource
  59.     }
  60.  
  61.     ShaderEffectSource {
  62.         id: cacheItem
  63.         anchors.fill: shaderItem
  64.         visible: rootItem.cached
  65.         sourceItem: shaderItem
  66.         live: true
  67.         hideSource: visible
  68.         smooth: rootItem.blur > 0
  69.     }
  70.  
  71.     property string __internalBlurVertexShader: "
  72.         attribute highp vec4 qt_Vertex;
  73.         attribute highp vec2 qt_MultiTexCoord0;
  74.         uniform highp mat4 qt_Matrix;
  75.         uniform highp float yStep;
  76.         uniform highp float xStep;
  77.         varying highp vec2 qt_TexCoord0;
  78.         varying highp vec2 qt_TexCoord1;
  79.         varying highp vec2 qt_TexCoord2;
  80.         varying highp vec2 qt_TexCoord3;
  81.  
  82.         void main() {
  83.             qt_TexCoord0 = vec2(qt_MultiTexCoord0.x + xStep, qt_MultiTexCoord0.y + yStep * 0.36);
  84.             qt_TexCoord1 = vec2(qt_MultiTexCoord0.x + xStep * 0.36, qt_MultiTexCoord0.y - yStep);
  85.             qt_TexCoord2 = vec2(qt_MultiTexCoord0.x - xStep * 0.36, qt_MultiTexCoord0.y + yStep);
  86.             qt_TexCoord3 = vec2(qt_MultiTexCoord0.x - xStep, qt_MultiTexCoord0.y - yStep * 0.36);
  87.             gl_Position = qt_Matrix * qt_Vertex;
  88.         }
  89.     "
  90.  
  91.     property string __internalBlurFragmentShader: "
  92.         uniform lowp sampler2D source;
  93.         uniform lowp float qt_Opacity;
  94.         varying highp vec2 qt_TexCoord0;
  95.         varying highp vec2 qt_TexCoord1;
  96.         varying highp vec2 qt_TexCoord2;
  97.         varying highp vec2 qt_TexCoord3;
  98.  
  99.         void main() {
  100.             highp vec4 sourceColor = (texture2D(source, qt_TexCoord0) +
  101.             texture2D(source, qt_TexCoord1) +
  102.             texture2D(source, qt_TexCoord2) +
  103.             texture2D(source, qt_TexCoord3)) * 0.25;
  104.             gl_FragColor = sourceColor * qt_Opacity;
  105.         }
  106.    "
  107.  
  108.     ShaderEffect {
  109.         id: mask0
  110.         property variant source: maskSourceProxy.output
  111.         anchors.fill: parent
  112.         visible: false
  113.         smooth: true
  114.     }
  115.  
  116.    ShaderEffectSource {
  117.        id: masklevel1
  118.        width: Math.ceil(shaderItem.width / 32) * 32
  119.        height: Math.ceil(shaderItem.height / 32) * 32
  120.        sourceItem: mask0
  121.        hideSource: rootItem.visible
  122.        sourceRect: transparentBorder ? Qt.rect(-64, -64, shaderItem.width, shaderItem.height) : Qt.rect(0, 0, 0, 0)
  123.        visible: false
  124.        smooth: rootItem.blur > 0
  125.    }
  126.  
  127.     ShaderEffect {
  128.         id: level0
  129.         property variant source: sourceProxy.output
  130.         anchors.fill: parent
  131.         visible: false
  132.         smooth: true
  133.     }
  134.  
  135.     ShaderEffectSource {
  136.         id: level1
  137.         width: Math.ceil(shaderItem.width / 32) * 32
  138.         height: Math.ceil(shaderItem.height / 32) * 32
  139.         sourceItem: level0
  140.         hideSource: rootItem.visible
  141.         sourceRect: transparentBorder ? Qt.rect(-64, -64, shaderItem.width, shaderItem.height) : Qt.rect(0, 0, 0, 0)
  142.         visible: false
  143.         smooth: rootItem.blur > 0
  144.     }
  145.  
  146.     ShaderEffect {
  147.         id: effect1
  148.         property variant source: level1
  149.         property real yStep: 1/height
  150.         property real xStep: 1/width
  151.         anchors.fill: level2
  152.         visible: false
  153.         smooth: true
  154.         vertexShader: __internalBlurVertexShader
  155.         fragmentShader: __internalBlurFragmentShader
  156.     }
  157.  
  158.     ShaderEffectSource {
  159.         id: level2
  160.         width: level1.width / 2
  161.         height: level1.height / 2
  162.         sourceItem: effect1
  163.         hideSource: rootItem.visible
  164.         visible: false
  165.         smooth: true
  166.     }
  167.  
  168.     ShaderEffect {
  169.         id: effect2
  170.         property variant source: level2
  171.         property real yStep: 1/height
  172.         property real xStep: 1/width
  173.         anchors.fill: level3
  174.         visible: false
  175.         smooth: true
  176.         vertexShader: __internalBlurVertexShader
  177.         fragmentShader: __internalBlurFragmentShader
  178.     }
  179.  
  180.     ShaderEffectSource {
  181.         id: level3
  182.         width: level2.width / 2
  183.         height: level2.height / 2
  184.         sourceItem: effect2
  185.         hideSource: rootItem.visible
  186.         visible: false
  187.         smooth: true
  188.     }
  189.  
  190.     ShaderEffect {
  191.         id: effect3
  192.         property variant source: level3
  193.         property real yStep: 1/height
  194.         property real xStep: 1/width
  195.         anchors.fill: level4
  196.         visible: false
  197.         smooth: true
  198.         vertexShader: __internalBlurVertexShader
  199.         fragmentShader: __internalBlurFragmentShader
  200.     }
  201.  
  202.     ShaderEffectSource {
  203.         id: level4
  204.         width: level3.width / 2
  205.         height: level3.height / 2
  206.         sourceItem: effect3
  207.         hideSource: rootItem.visible
  208.         visible: false
  209.         smooth: true
  210.     }
  211.  
  212.     ShaderEffect {
  213.         id: effect4
  214.         property variant source: level4
  215.         property real yStep: 1/height
  216.         property real xStep: 1/width
  217.         anchors.fill: level5
  218.         visible: false
  219.         smooth: true
  220.         vertexShader: __internalBlurVertexShader
  221.         fragmentShader: __internalBlurFragmentShader
  222.     }
  223.  
  224.     ShaderEffectSource {
  225.         id: level5
  226.         width: level4.width / 2
  227.         height: level4.height / 2
  228.         sourceItem: effect4
  229.         hideSource: rootItem.visible
  230.         visible: false
  231.         smooth: true
  232.     }
  233.  
  234.     ShaderEffect {
  235.         id: effect5
  236.         property variant source: level5
  237.         property real yStep: 1/height
  238.         property real xStep: 1/width
  239.         anchors.fill: level6
  240.         visible: false
  241.         smooth: true
  242.         vertexShader: __internalBlurVertexShader
  243.         fragmentShader: __internalBlurFragmentShader
  244.     }
  245.  
  246.     ShaderEffectSource {
  247.         id: level6
  248.         width: level5.width / 2
  249.         height: level5.height / 2
  250.         sourceItem: effect5
  251.         hideSource: rootItem.visible
  252.         visible: false
  253.         smooth: true
  254.     }
  255.  
  256.     ShaderEffect {
  257.         id: shaderItem
  258.         property variant mask: masklevel1
  259.         property variant source1: level1
  260.         property variant source2: level2
  261.         property variant source3: level3
  262.         property variant source4: level4
  263.         property variant source5: level5
  264.         property variant source6: level6
  265.         property real lod: Math.sqrt(rootItem.blur) * 1.2 - 0.2
  266.         property real weight1
  267.         property real weight2
  268.         property real weight3
  269.         property real weight4
  270.         property real weight5
  271.         property real weight6
  272.  
  273.         x: transparentBorder ? -64 : 0
  274.         y: transparentBorder ? -64 : 0
  275.         width: transparentBorder ? parent.width + 128 : parent.width
  276.         height: transparentBorder ? parent.height + 128 : parent.height
  277.  
  278.         fragmentShader: "
  279.             uniform lowp sampler2D mask;
  280.             uniform lowp sampler2D source1;
  281.             uniform lowp sampler2D source2;
  282.             uniform lowp sampler2D source3;
  283.             uniform lowp sampler2D source4;
  284.             uniform lowp sampler2D source5;
  285.             uniform lowp sampler2D source6;
  286.             uniform lowp float lod;
  287.             uniform lowp float qt_Opacity;
  288.             varying mediump vec2 qt_TexCoord0;
  289.  
  290.             mediump float weight(mediump float v) {
  291.                 if (v <= 0.0)
  292.                     return 1.0;
  293.  
  294.                 if (v >= 0.5)
  295.                     return 0.0;
  296.  
  297.                 return 1.0 - v * 2.0;
  298.             }
  299.  
  300.             void main() {
  301.  
  302.                 lowp vec4 maskColor = texture2D(mask, qt_TexCoord0);
  303.                 mediump float l = lod * maskColor.a;
  304.  
  305.                 mediump float w1 = weight(abs(l - 0.100));
  306.                 mediump float w2 = weight(abs(l - 0.300));
  307.                 mediump float w3 = weight(abs(l - 0.500));
  308.                 mediump float w4 = weight(abs(l - 0.700));
  309.                 mediump float w5 = weight(abs(l - 0.900));
  310.                 mediump float w6 = weight(abs(l - 1.100));
  311.  
  312.                 mediump float sum = w1 + w2 + w3 + w4 + w5 + w6;
  313.                 mediump float weight1 = w1 / sum;
  314.                 mediump float weight2 = w2 / sum;
  315.                 mediump float weight3 = w3 / sum;
  316.                 mediump float weight4 = w4 / sum;
  317.                 mediump float weight5 = w5 / sum;
  318.                 mediump float weight6 = w6 / sum;
  319.  
  320.                 lowp vec4 sourceColor = texture2D(source1, qt_TexCoord0) * weight1;
  321.                 sourceColor += texture2D(source2, qt_TexCoord0) * weight2;
  322.                 sourceColor += texture2D(source3, qt_TexCoord0) * weight3;
  323.                 sourceColor += texture2D(source4, qt_TexCoord0) * weight4;
  324.                 sourceColor += texture2D(source5, qt_TexCoord0) * weight5;
  325.                 sourceColor += texture2D(source6, qt_TexCoord0) * weight6;
  326.  
  327.                 gl_FragColor = sourceColor * qt_Opacity;
  328.  
  329.             }
  330.         "
  331.     }
  332. }
  333.